package com.yirui.bridge.udp.parser;

import com.yirui.bridge.udp.DataParser;
import io.netty.buffer.ByteBuf;

import java.util.Map;

/**
 * @author Dujie
 * @create 2021/11/25
 * @since 1.0.0
 */
public class Item0cParser implements DataParser {
    @Override
    public Object parse(ByteBuf buffer, int itemIndex, Map container) {
        int val = buffer.getByte(6);
        Object value = val;
        switch (itemIndex){
            case 0x04:
            case 0x09:
                if(buffer.getByte(5) == 0xFF){
                    val  = -val;
                }else{
                    val = val;
                }
                value = val;
            case 0x0f:
                value = val/100.0f;

        }
        int channel = buffer.getByte(8);
        container.put( String.format("%02x_%s",itemIndex, channel+1), value);
        return null;
    }


    @Override
    public boolean isSingleValue() {
        return false;
    }
}
